﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Common
{
    public class ServerProfile
    {
        public string serverIp;
        public int serverPort;
        public int maxTaskCount; //最大分配任务数


        /// <summary>
        /// 配置的cloud根目录
        /// </summary>
        public List<string> PathList;

        public ServerProfile()
        {

        }

        public ServerProfile(bool bServer)
        {
            PathList = new List<string>();
            string path = AppDomain.CurrentDomain.BaseDirectory;
            if (!path.EndsWith(@"\"))
                path += @"\";
            string inifilename = "common.ini";
            string iniFile = path + inifilename;

            if (File.Exists(iniFile))
            {
                Common.IniFile ini = new Common.IniFile(iniFile);

                serverIp = ini.IniReadValue("SocketServer", "ip");
                if (string.IsNullOrEmpty(serverIp))
                {
                    serverIp = Common.LocalIP.GetLocalIPV4();//服务器ip直接读取本机ip地址
                }

                string maxTask = ini.IniReadValue("SocketServer","maxTaskCount");
                Int32.TryParse(maxTask, out maxTaskCount);

                string port = ini.IniReadValue("SocketServer", "port");
                Int32.TryParse(port, out serverPort);

                int pathcount;
                Int32.TryParse(ini.IniReadValue("CloudPathCount", "pathCount"), out pathcount);
                for (int i = 0; i < pathcount; i++)
                {
                    StringBuilder sourcePath = new StringBuilder("sourcePath");
                    sourcePath.Append(i);
                    PathList.Add(ini.IniReadValue("CloudPath", sourcePath.ToString()));
                }
            }
            else
            {
                Log.Error("common.ini"+"配置文件不存在");
            }

        }
    }
}
